package lc;
import org.junit.*;
public class Ex1047 {
    class Solution {
        public String removeDuplicates(String s) {
            boolean flag = true;
            char[] cs;
            String left, right;
            loop: while (true) {
                cs = s.toCharArray();
                flag = true;
                for (int i = 1; i < cs.length; i++) {
                    if (cs[i] == cs[i - 1]) {
                        flag = false;
                        left = i > 1 ? s.substring(0, i - 1) : "";
                        right = i < cs.length - 1 ? s.substring(i + 1) : "";
                        s = left + right;
                        continue loop;
                    } 
                }
                if (flag) {
                    break loop;
                }
            }
            return s;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println(s.removeDuplicates("abbaca"));        
    }
}
